package com.itheima.web.controller;

import com.itheima.domain.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/page")
public class UserController  {

    @RequestMapping("/login")

    public ModelAndView login(User user, ModelAndView modelAndView) {
        String username = user.getUsername();
        String password = user.getPassword();
        if (("").equals(username)) {
            System.out.println("登录失败");
            modelAndView.addObject("msg", "用户名不能空");
            modelAndView.setViewName("login");
            return modelAndView;
        }
        if (("123456").equals(password)) {
            System.out.println("登陆成功");
            modelAndView.addObject("username", username);
            modelAndView.setViewName("success");
            return modelAndView;
        } else {
            modelAndView.addObject("username", "username");
            modelAndView.addObject("msg", "密码错误");
            System.out.println("密码错误");
            modelAndView.setViewName("login");
            return modelAndView;
        }


    }
    @RequestMapping("/loginPage")
    public String loginPage(){
        return "login";
    }
}
